package com.lyy.worker;

import com.lyy.utils.RabbitMqUtils;
import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;

/**
 * 工作线程相当于消费者
 */
public class consumer01 {
    public static final String QUEUE_NAME ="hello";

    public static void main(String[] args) throws Exception {
        Channel channel = RabbitMqUtils.getChannel();
        DeliverCallback deliverCallback=(consumerTag, message)->{
            System.out.println("接收到的消息是"+new String(message.getBody()));

        };

        CancelCallback cancelCallback= consumerTag->{
            System.out.println("消息消费被中断");
        };

        System.out.println("consumer02等待接收消息....");

        channel.basicConsume(QUEUE_NAME,true,deliverCallback,cancelCallback);
    }

}
